//
//  XC_tabBarViewController.m
//  NBProduct
//
//  Created by hl on 15/12/9.
//  Copyright (c) 2015年 ping. All rights reserved.
//

#import "XC_tabBarViewController.h"

@interface XC_tabBarViewController ()

@end

@implementation XC_tabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _labAry = [[NSMutableArray alloc]init];
    _btnAry = [[NSMutableArray alloc]init];
    _zhengChangAry = @[@"主页.png",@"商城.png",@"照片冲印1.png",@"我0",@"商铺-图标0.png"];
    _highlightAry = @[@"主页0.png",@"商城0.png",@"照片冲印.png",@"我00.png",@"商铺-图标.png"];
    NSArray *textAry = @[@"首页",@"商铺",@"冲印",@"我的",@"购物车"];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeBtn) name:@"ChangeBtn" object:nil];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(jiaZhengchangeBtn) name:@"JiaZhengChangeBtn" object:nil];
    
    self.tabBar.hidden = YES;
    
    UIImageView *tab_bac = [[UIImageView alloc]initWithFrame:CGRectMake(0, self.tabBar.frame.origin.y -10, KScreenWidth, 60)];
    
    
    tab_bac.image = [UIImage imageNamed:@"背景色1"];
    [self.view addSubview:tab_bac];
    
    for (int i = 0; i < Num; i++) {
        UIButton * tabBtn;
        UILabel *tabLab;
        if (i == 0) {
            tabBtn = [[UIButton alloc]initWithFrame:CGRectMake(KScreenWidth / Num * i + self.tabBar.frame.origin.x, self.tabBar.frame.origin.y, KScreenWidth  / Num, 35)];
            tabLab = [[UILabel alloc]initWithFrame:CGRectMake(KScreenWidth / Num * i + self.tabBar.frame.origin.x, self.tabBar.frame.origin.y + 30, KScreenWidth  / Num, 20)];
            tabLab.text = [textAry objectAtIndex:i];
            tabLab.textColor = TuBIAODianJi;
            tabLab.font = [UIFont systemFontOfSize:11];
            tabLab.textAlignment = NSTextAlignmentCenter;
            [tabBtn setImage:[UIImage imageNamed:[_highlightAry objectAtIndex:i]] forState:UIControlStateNormal];
        }else{
            
            tabBtn = [[UIButton alloc]initWithFrame:CGRectMake(KScreenWidth / Num * i + self.tabBar.frame.origin.x, self.tabBar.frame.origin.y, KScreenWidth  / Num, 35)];
            tabLab = [[UILabel alloc]initWithFrame:CGRectMake(KScreenWidth / Num * i + self.tabBar.frame.origin.x, self.tabBar.frame.origin.y + 30, KScreenWidth  / Num, 20)];
            if (i == 2) {
                tabBtn.frame = CGRectMake(KScreenWidth / Num * i + self.tabBar.frame.origin.x, self.tabBar.frame.origin.y - 3, KScreenWidth  / Num + 3, 33);
            }
            tabLab.text = [textAry objectAtIndex:i];
            tabLab.textColor = TUBIAOCOLOR;
            tabLab.font = [UIFont systemFontOfSize:11];
            tabLab.textAlignment = NSTextAlignmentCenter;
            [tabBtn setImage:[UIImage imageNamed:[_zhengChangAry objectAtIndex:i]] forState:UIControlStateNormal];
        }
        
        tabBtn.tag = i;
        [self.view addSubview:tabLab];
        [_labAry addObject:tabLab];
        [_btnAry addObject:tabBtn];
        [tabBtn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:tabBtn];
        
    }
}

-(void)changeBtn{
    self.selectedIndex = 2;
    for (int i = 0; i < _zhengChangAry.count; i++) {
        [[_btnAry objectAtIndex:i]setImage:[UIImage imageNamed:[_zhengChangAry objectAtIndex:i]] forState:UIControlStateNormal];
        ((UILabel *)[_labAry objectAtIndex:i]).textColor = TUBIAOCOLOR;
    }
    
    [[_btnAry objectAtIndex:2] setImage:[UIImage imageNamed:[_highlightAry objectAtIndex:2]] forState:UIControlStateNormal];
    ((UILabel *)[_labAry objectAtIndex:2]).textColor = TuBIAODianJi;
}

-(void)jiaZhengchangeBtn{
    self.selectedIndex = 1;
    for (int i = 0; i < _zhengChangAry.count; i++) {
        [[_btnAry objectAtIndex:i]setImage:[UIImage imageNamed:[_zhengChangAry objectAtIndex:i]] forState:UIControlStateNormal];
        ((UILabel *)[_labAry objectAtIndex:i]).textColor = TUBIAOCOLOR;
    }
    
    [[_btnAry objectAtIndex:1] setImage:[UIImage imageNamed:[_highlightAry objectAtIndex:2]] forState:UIControlStateNormal];
    ((UILabel *)[_labAry objectAtIndex:2]).textColor = TuBIAODianJi;
    
}


-(void)click:(UIButton *)btn{
    self.selectedIndex = btn.tag;
    for (int i = 0; i < _zhengChangAry.count; i++) {
        [[_btnAry objectAtIndex:i]setImage:[UIImage imageNamed:[_zhengChangAry objectAtIndex:i]] forState:UIControlStateNormal];
        ((UILabel *)[_labAry objectAtIndex:i]).textColor = [UIColor lightGrayColor];
    }
    [btn setImage:[UIImage imageNamed:[_highlightAry objectAtIndex:btn.tag]] forState:UIControlStateNormal];
    ((UILabel *)[_labAry objectAtIndex:btn.tag]).textColor = TuBIAODianJi;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
